home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / Software / Trial / TestTrack Pro 6 / ttprowininstall.exe / %LSMAINDIR% / LicenseServer Help / wwhelp / wwhimpl / js / scripts / search.js < prev    next >
Encoding:
JavaScript  |  2003-12-12  |  32.5 KB  |  1,151 lines

  1. // Copyright (c) 2000-2001 Quadralay Corporation.  All rights reserved.
  2. //
  3.  
  4. function  WWHSearch_Object()
  5. {
  6.   this.mbPanelInitialized      = false;
  7.   this.mPanelAnchor            = null;
  8.   this.mPanelTabTitle          = WWHFrame.WWHJavaScript.mMessages.mTabsSearchLabel;
  9.   this.mbBookSearchInfoLoaded  = false;
  10.   this.mInitIndex              = 0;
  11.   this.mBookSearchInfoList     = new Array();
  12.   this.mSavedSearchWords       = "";
  13.   this.mSavedSearchScope       = 0;
  14.   this.mSearchWordList         = new Array();
  15.   this.mSearchWordRegExpList   = new Array();
  16.   this.mBookIndex              = 0;
  17.   this.mBookMatchesList        = new Array();
  18.   this.mCombinedResults        = new WWHSearchResults_Object();
  19.  
  20.   this.fInitHeadHTML           = WWHSearch_InitHeadHTML;
  21.   this.fInitBodyHTML           = WWHSearch_InitBodyHTML;
  22.   this.fInitLoadBookSearchInfo = WWHSearch_InitLoadBookSearchInfo;
  23.   this.fHeadHTML               = WWHSearch_HeadHTML;
  24.   this.fStartHTMLSegments      = WWHSearch_StartHTMLSegments;
  25.   this.fAdvanceHTMLSegment     = WWHSearch_AdvanceHTMLSegment;
  26.   this.fGetHTMLSegment         = WWHSearch_GetHTMLSegment;
  27.   this.fEndHTMLSegments        = WWHSearch_EndHTMLSegments;
  28.   this.fHoverTextTranslate     = WWHSearch_HoverTextTranslate;
  29.   this.fHoverTextFormat        = WWHSearch_HoverTextFormat;
  30.   this.fDisplaySearchForm      = WWHSearch_DisplaySearchForm;
  31.   this.fSubmit                 = WWHSearch_Submit;
  32.   this.fSetSearchWords         = WWHSearch_SetSearchWords;
  33.   this.fCheckForMatch          = WWHSearch_CheckForMatch;
  34.   this.fSearchComplete         = WWHSearch_SearchComplete;
  35.   this.fCombineResults         = WWHSearch_CombineResults;
  36.   this.fShowEntry              = WWHSearch_ShowEntry;
  37. }
  38.  
  39. function  WWHSearch_InitHeadHTML()
  40. {
  41.   var  InitHeadHTML = "";
  42.  
  43.  
  44.   return InitHeadHTML;
  45. }
  46.  
  47. function  WWHSearch_InitBodyHTML()
  48. {
  49.   var  HTML = new WWHStringBuffer_Object();
  50.   var  BookList = WWHFrame.WWHHelp.mBooks.mBookList;
  51.   var  MaxIndex;
  52.   var  Index;
  53.   var  MaxBookIndex;
  54.   var  BookIndex;
  55.   var  BookDirectory;
  56.  
  57.  
  58.   if ( ! this.mbBookSearchInfoLoaded)
  59.   {
  60.     // Display initializing message
  61.     //
  62.     HTML.fAppend("<h2>" + WWHFrame.WWHJavaScript.mMessages.mInitializingMessage + "</h2>\n");
  63.  
  64.     // Load search info
  65.     //
  66.     this.mInitIndex = 0;
  67.     for (MaxIndex = BookList.length, Index = 0 ; Index < MaxIndex ; Index++)
  68.     {
  69.       // Reference search info
  70.       //
  71.       HTML.fAppend("<script language=\"JavaScript1.2\" src=\"" + WWHFrame.WWHHelp.mHelpURLPrefix + WWHStringUtilities_RestoreEscapedSpaces(BookList[Index].mDirectory) + "wwhdata/js/search.js\"></script>\n");
  72.  
  73.       // Load search info for current book
  74.       //
  75.       HTML.fAppend("<script language=\"JavaScript1.2\" src=\"" + WWHFrame.WWHHelp.mHelpURLPrefix + "wwhelp/wwhimpl/js/scripts/search1s.js\"></script>\n");
  76.     }
  77.   }
  78.   else  // Perform search
  79.   {
  80.     // Display searching message
  81.     //
  82.     HTML.fAppend("<h2>" + WWHFrame.WWHJavaScript.mMessages.mSearchSearchingMessage + "</h2>\n");
  83.  
  84.     // Handle single book search
  85.     //
  86.     if (this.mSavedSearchScope > 0)
  87.     {
  88.       MaxBookIndex = this.mSavedSearchScope;
  89.       BookIndex    = this.mSavedSearchScope - 1;
  90.     }
  91.     else
  92.     {
  93.       MaxBookIndex = BookList.length;
  94.       BookIndex    = 0;
  95.     }
  96.  
  97.     // Generate search actions
  98.     //
  99.     this.mBookIndex = BookIndex;
  100.     for ( ; BookIndex < MaxBookIndex ; BookIndex++)
  101.     {
  102.       BookDirectory = BookList[BookIndex].mDirectory;
  103.  
  104.       for (MaxIndex = this.mBookSearchInfoList[BookIndex].mSearchFileCount, Index = 0 ; Index < MaxIndex ; Index++)
  105.       {
  106.         HTML.fAppend("<script type=\"text/javascript\" language=\"JavaScript1.2\" src=\"" + WWHFrame.WWHHelp.mHelpURLPrefix + WWHStringUtilities_RestoreEscapedSpaces(BookDirectory) + "wwhdata/js/search/search" + Index + ".js\"></script>\n");
  107.         HTML.fAppend("<script type=\"text/javascript\" language=\"JavaScript1.2\" src=\"" + WWHFrame.WWHHelp.mHelpURLPrefix + "wwhelp/wwhimpl/js/scripts/search2s.js\"></script>\n");
  108.       }
  109.  
  110.       HTML.fAppend("<script type=\"text/javascript\" language=\"JavaScript1.2\" src=\"" + WWHFrame.WWHHelp.mHelpURLPrefix + "wwhelp/wwhimpl/js/scripts/search3s.js\"></script>\n");
  111.     }
  112.  
  113.     HTML.fAppend("<script type=\"text/javascript\" language=\"JavaScript1.2\" src=\"" + WWHFrame.WWHHelp.mHelpURLPrefix + "wwhelp/wwhimpl/js/scripts/search4s.js\"></script>\n");
  114.   }
  115.  
  116.   return HTML.fGetBuffer();
  117. }
  118.  
  119. function  WWHSearch_InitLoadBookSearchInfo(ParamSearchFileCount,
  120.                                            ParamMinimumWordLength,
  121.                                            ParamSearchSkipWordsFunc)
  122. {
  123.   // Load book search info
  124.   //
  125.   this.mBookSearchInfoList[this.mInitIndex] = new WWHBookSearchInfo_Object(ParamSearchFileCount, ParamMinimumWordLength);
  126.   ParamSearchSkipWordsFunc(this.mBookSearchInfoList[this.mInitIndex]);
  127.  
  128.   // Create match objects for each book
  129.   //
  130.   this.mBookMatchesList[this.mBookMatchesList.length] = new WWHSearchBookMatches_Object();
  131.  
  132.   // Increment init book index
  133.   //
  134.   this.mInitIndex++;
  135.  
  136.   // Mark initialized if done
  137.   //
  138.   if (this.mInitIndex == WWHFrame.WWHHelp.mBooks.mBookList.length)
  139.   {
  140.     this.mbPanelInitialized = true;
  141.     this.mbBookSearchInfoLoaded = true;
  142.   }
  143. }
  144.  
  145. function  WWHSearch_HeadHTML()
  146. {
  147.   var  HTML = new WWHStringBuffer_Object();
  148.   var  Settings = WWHFrame.WWHJavaScript.mSettings.mSearch;
  149.  
  150.  
  151.   // Generate style section
  152.   //
  153.   HTML.fAppend("<style type=\"text/css\">\n");
  154.   HTML.fAppend(" <!--\n");
  155.   HTML.fAppend("  a  {\n");
  156.   HTML.fAppend("       text-decoration: none;\n");
  157.   HTML.fAppend("       color: " + Settings.mEnabledColor + ";\n");
  158.   HTML.fAppend("     }\n");
  159.   HTML.fAppend("  p  {\n");
  160.   HTML.fAppend("       margin-top: 1pt;\n");
  161.   HTML.fAppend("       margin-bottom: 1pt;\n");
  162.   HTML.fAppend("       " + Settings.mFontStyle + ";\n");
  163.   HTML.fAppend("     }\n");
  164.   HTML.fAppend("  ol {\n");
  165.   HTML.fAppend("       margin-top: 1pt;\n");
  166.   HTML.fAppend("       margin-bottom: 1pt;\n");
  167.   if (Settings.mbShowRank)
  168.   {
  169.     HTML.fAppend("       " + Settings.mFontStyle + ";\n");
  170.   }
  171.   else
  172.   {
  173.     HTML.fAppend("       list-style: none;\n");
  174.   }
  175.   HTML.fAppend("     }\n");
  176.   HTML.fAppend("  li {\n");
  177.   HTML.fAppend("       margin-top: 2pt;\n");
  178.   HTML.fAppend("       margin-bottom: 0pt;\n");
  179.   HTML.fAppend("       " + Settings.mFontStyle + ";\n");
  180.   HTML.fAppend("     }\n");
  181.   HTML.fAppend(" -->\n");
  182.   HTML.fAppend("</style>\n");
  183.  
  184.   return HTML.fGetBuffer();
  185. }
  186.  
  187. function  WWHSearch_StartHTMLSegments()
  188. {
  189.   var  HTML = new WWHStringBuffer_Object();
  190.  
  191.  
  192.   if (this.mbPanelInitialized)
  193.   {
  194.     HTML.fAppend(this.fDisplaySearchForm());
  195.  
  196.     if (this.mSavedSearchWords.length == 0)
  197.     {
  198.       HTML.fAppend("<h3>" + WWHFrame.WWHJavaScript.mMessages.mSearchDefaultMessage + "</h3>\n");
  199.     }
  200.     else if ((typeof this.mCombinedResults.mEntries != "undefined") &&
  201.              (this.mCombinedResults.mEntries.length > 0))
  202.     {
  203.       this.mCombinedResults.fDisplayReset();
  204.     }
  205.     else
  206.     {
  207.       HTML.fAppend("<h3>" + WWHFrame.WWHJavaScript.mMessages.mSearchNothingFoundMessage + "</h3>\n");
  208.     }
  209.   }
  210.  
  211.   // Define accessor functions to reduce file size
  212.   //
  213.   HTML.fAppend("<script type=\"text/javascript\" language=\"JavaScript1.2\">\n");
  214.   HTML.fAppend(" <!--\n");
  215.   HTML.fAppend("  function  fC(ParamEntryID)\n");
  216.   HTML.fAppend("  {\n");
  217.   HTML.fAppend("    WWHFrame.WWHSearch.fShowEntry(ParamEntryID);\n");
  218.   HTML.fAppend("  }\n");
  219.   HTML.fAppend("\n");
  220.   HTML.fAppend("  function  fS(ParamEntryID,\n");
  221.   HTML.fAppend("               ParamEvent)\n");
  222.   HTML.fAppend("  {\n");
  223.   HTML.fAppend("    WWHFrame.WWHJavaScript.mPanels.mPopup.fShow(ParamEntryID, ParamEvent);\n");
  224.   HTML.fAppend("  }\n");
  225.   HTML.fAppend("\n");
  226.   HTML.fAppend("  function  fH()\n");
  227.   HTML.fAppend("  {\n");
  228.   HTML.fAppend("    WWHFrame.WWHJavaScript.mPanels.mPopup.fHide();\n");
  229.   HTML.fAppend("  }\n");
  230.   HTML.fAppend(" // -->\n");
  231.   HTML.fAppend("</script>\n");
  232.  
  233.   return HTML.fGetBuffer();
  234. }
  235.  
  236. function  WWHSearch_AdvanceHTMLSegment()
  237. {
  238.   var  bSegmentCreated = false;
  239.  
  240.  
  241.   if (this.mbPanelInitialized)
  242.   {
  243.     bSegmentCreated = this.mCombinedResults.fDisplayAdvance();
  244.   }
  245.  
  246.   return bSegmentCreated;
  247. }
  248.  
  249. function  WWHSearch_GetHTMLSegment()
  250. {
  251.   return this.mCombinedResults.mHTMLSegment.fGetBuffer();
  252. }
  253.  
  254. function  WWHSearch_EndHTMLSegments()
  255. {
  256.   return "";
  257. }
  258.  
  259. function  WWHSearch_HoverTextTranslate(ParamEntryID)
  260. {
  261.   var  HTML     = "";
  262.   var  BookList = WWHFrame.WWHHelp.mBooks.mBookList;
  263.   var  Settings = WWHFrame.WWHJavaScript.mSettings.mSearch;
  264.   var  Messages = WWHFrame.WWHJavaScript.mMessages;
  265.   var  Entry;
  266.   var  Rank = "";
  267.   var  Title;
  268.   var  Book = "";
  269.   var  Format;
  270.  
  271.  
  272.   // Retrieve specified entry
  273.   //
  274.   Entry = this.mCombinedResults.mEntries[ParamEntryID];
  275.  
  276.   // Get Rank
  277.   //
  278.   if (Settings.mbShowRank)
  279.   {
  280.     Rank = Math.floor((Entry.mScore / this.mCombinedResults.mMaxScore) * 100) + "%";
  281.   }
  282.  
  283.   // Get Title
  284.   //
  285.   Title = Entry.mTitle;
  286.  
  287.   // Get Book
  288.   //
  289.   if (Settings.mbShowBook)
  290.   {
  291.     if ((BookList.length > 1) &&                 // More than one book exists
  292.         (this.mCombinedResults.mSortedBy == 1))  // By Score
  293.     {
  294.       Book = BookList[Entry.mBookIndex].mTitle;
  295.     }
  296.   }
  297.  
  298.   // Format for display
  299.   //
  300.   if ((Rank.length == 0) &&
  301.       (Book.length == 0))
  302.   {
  303.     // Simple format, just the title
  304.     //
  305.     HTML = Title;
  306.   }
  307.   else
  308.   {
  309.     Format = " align=\"left\" valign=\"top\"><span style=\"" + WWHFrame.WWHJavaScript.mSettings.mHoverText.mFontStyle + "\">";
  310.  
  311.     // Complex format, requires a table
  312.     //
  313.     HTML += "<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">";
  314.     if (Rank.length > 0)
  315.     {
  316.       HTML += "<tr>";
  317.       HTML += "<th" + Format + Messages.mSearchRankLabel + "</span></th>";
  318.       HTML += "<td" + Format + Rank + "</span></td>";
  319.       HTML += "</tr>";
  320.     }
  321.     HTML += "<tr>";
  322.     HTML += "<th" + Format + Messages.mSearchTitleLabel + "</span></th>";
  323.     HTML += "<td" + Format + Title + "</span></td>";
  324.     HTML += "</tr>";
  325.     if (Book.length > 0)
  326.     {
  327.       HTML += "<tr>";
  328.       HTML += "<th" + Format + Messages.mSearchBookLabel + "</span></th>";
  329.       HTML += "<td" + Format + Book + "</span></td>";
  330.       HTML += "</tr>";
  331.     }
  332.     HTML += "</table>";
  333.   }
  334.  
  335.   return HTML;
  336. }
  337.  
  338. function  WWHSearch_HoverTextFormat(ParamWidth,
  339.                                     ParamTextID,
  340.                                     ParamText)
  341. {
  342.   var  FormattedText   = "";
  343.   var  ForegroundColor = WWHFrame.WWHJavaScript.mSettings.mHoverText.mForegroundColor;
  344.   var  BackgroundColor = WWHFrame.WWHJavaScript.mSettings.mHoverText.mBackgroundColor;  
  345.   var  BorderColor     = WWHFrame.WWHJavaScript.mSettings.mHoverText.mBorderColor;
  346.   var  ImageDir        = WWHFrame.WWHHelp.mHelpURLPrefix + "wwhelp/wwhimpl/common/images";
  347.   var  ReqSpacer1w2h   = "<img src=\"" + ImageDir + "/spc1w2h.gif\" width=1 height=2>";
  348.   var  ReqSpacer2w1h   = "<img src=\"" + ImageDir + "/spc2w1h.gif\" width=2 height=1>";
  349.   var  ReqSpacer1w7h   = "<img src=\"" + ImageDir + "/spc1w7h.gif\" width=1 height=7>";
  350.   var  ReqSpacer5w1h   = "<img src=\"" + ImageDir + "/spc5w1h.gif\" width=5 height=1>";
  351.   var  Spacer1w2h      = ReqSpacer1w2h;
  352.   var  Spacer2w1h      = ReqSpacer2w1h;
  353.   var  Spacer1w7h      = ReqSpacer1w7h;
  354.   var  Spacer5w1h      = ReqSpacer5w1h;
  355.  
  356.  
  357.   // Netscape 6.x (Mozilla) renders table cells with graphics
  358.   // incorrectly inside of <div> tags that are rewritten on the fly
  359.   //
  360.   if (WWHFrame.WWHBrowserInfo.mBrowser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  361.   {
  362.     Spacer1w2h = "";
  363.     Spacer2w1h = "";
  364.     Spacer1w7h = "";
  365.     Spacer5w1h = "";
  366.   }
  367.  
  368.   FormattedText += "<table width=\"" + ParamWidth + "\" border=0 cellspacing=0 cellpadding=0 bgcolor=\"" + BackgroundColor + "\">";
  369.   FormattedText += " <tr>";
  370.   FormattedText += "  <td height=2 colspan=5 bgcolor=\"" + BorderColor + "\">" + Spacer1w2h + "</td>";
  371.   FormattedText += " </tr>";
  372.  
  373.   FormattedText += " <tr>";
  374.   FormattedText += "  <td height=7 bgcolor=\"" + BorderColor + "\">" + Spacer2w1h + "</td>";
  375.   FormattedText += "  <td height=7 colspan=3>" + Spacer1w7h + "</td>";
  376.   FormattedText += "  <td height=7 bgcolor=\"" + BorderColor + "\">" + Spacer2w1h + "</td>";
  377.   FormattedText += " </tr>";
  378.  
  379.   FormattedText += " <tr>";
  380.   FormattedText += "  <td bgcolor=\"" + BorderColor + "\">" + ReqSpacer2w1h + "</td>";
  381.   FormattedText += "  <td>" + ReqSpacer5w1h + "</td>";
  382.   FormattedText += "  <td width=\"100%\" id=\"" + ParamTextID + "\" style=\"color: " + ForegroundColor + " ; " + WWHFrame.WWHJavaScript.mSettings.mHoverText.mFontStyle + "\">" + ParamText + "</td>";
  383.   FormattedText += "  <td>" + ReqSpacer5w1h + "</td>";
  384.   FormattedText += "  <td bgcolor=\"" + BorderColor + "\">" + ReqSpacer2w1h + "</td>";
  385.   FormattedText += " </tr>";
  386.  
  387.   FormattedText += " <tr>";
  388.   FormattedText += "  <td height=7 bgcolor=\"" + BorderColor + "\">" + Spacer2w1h + "</td>";
  389.   FormattedText += "  <td height=7 colspan=3>" + Spacer1w7h + "</td>";
  390.   FormattedText += "  <td height=7 bgcolor=\"" + BorderColor + "\">" + Spacer2w1h + "</td>";
  391.   FormattedText += " </tr>";
  392.  
  393.   FormattedText += " <tr>";
  394.   FormattedText += "  <td height=2 colspan=5 bgcolor=\"" + BorderColor + "\">" + Spacer1w2h + "</td>";
  395.   FormattedText += " </tr>";
  396.   FormattedText += "</table>";
  397.  
  398.   return FormattedText;
  399. }
  400.  
  401. function  WWHSearch_DisplaySearchForm()
  402. {
  403.   var  HTML = "";
  404.   var  BookList = WWHFrame.WWHHelp.mBooks.mBookList;
  405.  
  406.  
  407.   HTML += "<form name=\"WWHSearchForm\" onSubmit=\"WWHFrame.WWHSearch.fSubmit();\">\n";
  408.   HTML += "<nobr>\n";
  409.   HTML += "<input type=\"text\" name=\"WWHSearchWordsText\" size=20 value=\"" + this.mSavedSearchWords + "\">\n";
  410.   HTML += "<input type=\"submit\" value=\"" + WWHFrame.WWHJavaScript.mMessages.mSearchButtonLabel + "\">\n";
  411.   HTML += "</nobr>\n";
  412.  
  413.   if (BookList.length > 1)
  414.   {
  415.     var  SelectedIndex = this.mSavedSearchScope - 1;
  416.     var  MaxIndex;
  417.     var  Index;
  418.  
  419.  
  420.     HTML += "<br>\n";
  421.     HTML += "<select name=\"WWHSearchScope\">\n";
  422.     HTML += "<option>" + WWHFrame.WWHJavaScript.mMessages.mSearchScopeAllLabel + "</option>\n";
  423.     for (MaxIndex = BookList.length, Index = 0 ; Index < MaxIndex ; Index++)
  424.     {
  425.       if (Index == SelectedIndex)
  426.       {
  427.         HTML += "<option selected>";
  428.       }
  429.       else
  430.       {
  431.         HTML += "<option>";
  432.       }
  433.  
  434.       HTML += BookList[Index].mTitle + "</option>\n";
  435.     }
  436.     HTML += "</select>\n";
  437.   }
  438.  
  439.   HTML += "</form>\n";
  440.  
  441.   return HTML;
  442. }
  443.  
  444. function  WWHSearch_Submit()
  445. {
  446.   var  SearchForm = WWHFrame.WWHNavigationFrame.WWHPanelFrame.document.forms["WWHSearchForm"];
  447.   var  NewSearchWords;
  448.   var  NewSearchScope;
  449.   var  bSearchChanged = false;
  450.  
  451.  
  452.   // Update search words
  453.   //
  454.   NewSearchWords = SearchForm.elements["WWHSearchWordsText"].value;
  455.   if (NewSearchWords != this.mSavedSearchWords)
  456.   {
  457.     this.mSavedSearchWords = NewSearchWords;
  458.  
  459.     bSearchChanged = true;
  460.   }
  461.  
  462.   // Update search scope
  463.   //
  464.   if (WWHFrame.WWHHelp.mBooks.mBookList.length > 1)
  465.   {
  466.     NewSearchScope = SearchForm.elements["WWHSearchScope"].selectedIndex;
  467.     if (NewSearchScope != this.mSavedSearchScope)
  468.     {
  469.       this.mSavedSearchScope = NewSearchScope;
  470.  
  471.       bSearchChanged = true;
  472.     }
  473.   }
  474.  
  475.   // Perform search if something changed
  476.   //
  477.   if (bSearchChanged)
  478.   {
  479.     if (this.mSavedSearchWords.length > 0)
  480.     {
  481.       var  MaxIndex;
  482.       var  Index;
  483.  
  484.  
  485.       // Clear previous results
  486.       //
  487.       for (MaxIndex = this.mBookMatchesList.length, Index = 0 ; Index < MaxIndex ; Index++)
  488.       {
  489.         this.mBookMatchesList[Index].fClear();
  490.       }
  491.       this.mCombinedResults.fClear();
  492.  
  493.       // Save/restore current position
  494.       //
  495.       WWHFrame.WWHJavaScript.mPanels.fSaveScrollPosition();
  496.  
  497.       // Perform search
  498.       //
  499.       this.fSetSearchWords(WWHStringUtilities_NormalizeSearchWords(this.mSavedSearchWords));
  500.       this.mbPanelInitialized = false;
  501.       setTimeout("WWHFrame.WWHJavaScript.mPanels.fDisplayPanel();", 50);  // Need to finish submit
  502.     }
  503.   }
  504.  
  505.   return bSearchChanged;
  506. }
  507.  
  508. function  WWHSearch_SetSearchWords(ParamSearchWordsString)
  509. {
  510.   // Workaround for stupid Netscape 4.x bug
  511.   //
  512.   var  StringWithSpace = "x x";
  513.   var  SearchWordList;
  514.   var  MaxIndex;
  515.   var  Index;
  516.   var  SearchWord;
  517.   var  SearchRegExpPattern;
  518.  
  519.  
  520.   // Clear search words
  521.   //
  522.   this.mSearchWordList.length = 0;
  523.   this.mSearchWordRegExpList.length = 0;
  524.  
  525.   // Add search words to hash
  526.   //
  527.   SearchWordList = ParamSearchWordsString.split(StringWithSpace.substring(1, 2));
  528.   for (MaxIndex = SearchWordList.length, Index = 0 ; Index < MaxIndex ; Index++)
  529.   {
  530.     // Skip 0 length words
  531.     //
  532.     if (SearchWordList[Index].length > 0)
  533.     {
  534.       // Add to search words hash
  535.       //
  536.       SearchWord = SearchWordList[Index].toLowerCase();
  537.       SearchRegExpPattern = WWHStringUtilities_WordToRegExpPattern(SearchWord);
  538.  
  539.       this.mSearchWordList[this.mSearchWordList.length] = SearchWord;
  540.       this.mSearchWordRegExpList[this.mSearchWordRegExpList.length] = new RegExp(SearchRegExpPattern, "i");
  541.     }
  542.   }
  543. }
  544.  
  545. function  WWHSearch_CheckForMatch(ParamSearchFunc)
  546. {
  547.   var  Count;
  548.   var  MaxIndex;
  549.   var  Index;
  550.   var  BookSearchInfoEntry;
  551.   var  SearchPattern;
  552.  
  553.  
  554.   Count = 0;
  555.   for (MaxIndex = this.mSearchWordList.length, Index = 0 ; Index < MaxIndex ; Index++)
  556.   {
  557.     BookSearchInfoEntry = this.mBookSearchInfoList[this.mBookIndex]
  558.  
  559.     if (this.mBookSearchInfoList[this.mBookIndex].fValidSearchWord(this.mSearchWordList[Index]))
  560.     {
  561.       BookMatchesListEntry = this.mBookMatchesList[this.mBookIndex];
  562.  
  563.       BookMatchesListEntry.fSetMatchedWordIndex(Count);
  564.  
  565.       SearchPattern = this.mSearchWordRegExpList[Index];
  566.       SearchPattern.t = SearchPattern.test;
  567.  
  568.       ParamSearchFunc(SearchPattern, BookMatchesListEntry);
  569.  
  570.       Count++;
  571.     }
  572.   }
  573. }
  574.  
  575. function  WWHSearch_SearchComplete()
  576. {
  577.   // Set flag so that results can be displayed
  578.   //
  579.   this.mbPanelInitialized = true;
  580.  
  581.   // Combine results for display
  582.   //
  583.   this.fCombineResults();
  584.  
  585.   // Sort results based on single or multi-book display
  586.   //
  587.   if ((WWHFrame.WWHHelp.mBooks.mBookList.length == 1) ||
  588.       (this.mSavedSearchScope > 0))
  589.   {
  590.     this.mCombinedResults.fSortByBookIndex();
  591.   }
  592.   else
  593.   {
  594.     this.mCombinedResults.fSortByScore();
  595.   }
  596. }
  597.  
  598. function  WWHSearch_CombineResults()
  599. {
  600.   var  MaxBookIndex;
  601.   var  BookIndex;
  602.   var  BookMatches;
  603.   var  BookListEntry;
  604.   var  FileID;
  605.   var  FileIndex;
  606.  
  607.  
  608.   this.mCombinedResults.fClear();
  609.   for (MaxBookIndex = this.mBookMatchesList.length, BookIndex = 0 ; BookIndex < MaxBookIndex ; BookIndex++)
  610.   {
  611.     BookMatches = this.mBookMatchesList[BookIndex];
  612.     BookListEntry = WWHFrame.WWHHelp.mBooks.mBookList[BookIndex];
  613.  
  614.     // Add results
  615.     //
  616.     BookMatches.fJoinFileScores();
  617.     for (FileID in BookMatches.mFileScores)
  618.     {
  619.       FileIndex = parseInt(FileID.substring(1, FileID.length));
  620.  
  621.       this.mCombinedResults.fAddEntry(BookIndex, FileIndex, BookMatches.mFileScores[FileID], BookListEntry.mFiles.fFileIndexToTitle(FileIndex));
  622.     }
  623.   }
  624. }
  625.  
  626. function  WWHSearch_ShowEntry(ParamIndex)
  627. {
  628.   this.mCombinedResults.fShowEntry(ParamIndex);
  629. }
  630.  
  631. function  WWHBookSearchInfo_Object(ParamSearchFileCount,
  632.                                    ParamMinimumWordLength)
  633. {
  634.   this.mSearchFileCount   = ParamSearchFileCount;
  635.   this.mMinimumWordLength = ParamMinimumWordLength;
  636.   this.mSkipWords         = new WWHBookSearchInfo_SkipWords_Object();
  637.  
  638.   this.fAddSkipWord     = WWHBookSearchInfo_AddSkipWord;
  639.   this.fA               = WWHBookSearchInfo_AddSkipWord;
  640.   this.fValidSearchWord = WWHBookSearchInfo_ValidSearchWord;
  641. }
  642.  
  643. function  WWHBookSearchInfo_AddSkipWord(ParamSkipWord)
  644. {
  645.   if (ParamSkipWord.length > 0)
  646.   {
  647.     this.mSkipWords[ParamSkipWord + "~"] = 1;
  648.   }
  649. }
  650.  
  651. function  WWHBookSearchInfo_ValidSearchWord(ParamSearchWord)
  652. {
  653.   var  bValid = true;
  654.  
  655.  
  656.   if ((ParamSearchWord.length < this.mMinimumWordLength) ||
  657.       (typeof this.mSkipWords[ParamSearchWord + "~"] == "number"))
  658.   {
  659.     bValid = false;
  660.   }
  661.  
  662.   return bValid;
  663. }
  664.  
  665. function  WWHBookSearchInfo_SkipWords_Object()
  666. {
  667. }
  668.  
  669. function  WWHSearchBookMatches_Object()
  670. {
  671.   this.mFirstMatchedWordIndex = -1;
  672.   this.mMatchedWordIndex      = -1;
  673.   this.mWordFileScores        = new Array();
  674.   this.mFileScores            = new WWHSearchBookMatches_FileScores_Object();
  675.  
  676.   this.fClear               = WWHSearchBookMatches_Clear;
  677.   this.fSetMatchedWordIndex = WWHSearchBookMatches_SetMatchedWordIndex;
  678.   this.fAddMatches          = WWHSearchBookMatches_AddMatches;
  679.   this.f                    = WWHSearchBookMatches_AddMatches;  // For smaller search files
  680.   this.fJoinFileScores      = WWHSearchBookMatches_JoinFileScores;
  681. }
  682.  
  683. function  WWHSearchBookMatches_Clear()
  684. {
  685.   this.mFirstMatchedWordIndex = -1;
  686.   this.mMatchedWordIndex      = -1;
  687.   this.mWordFileScores.length = 0;
  688.   this.mFileScores            = new WWHSearchBookMatches_FileScores_Object();
  689. }
  690.  
  691. function  WWHSearchBookMatches_SetMatchedWordIndex(ParamMatchedWordIndex)
  692. {
  693.   this.mMatchedWordIndex = ParamMatchedWordIndex;
  694.   if (ParamMatchedWordIndex == this.mWordFileScores.length)
  695.   {
  696.     this.mWordFileScores[this.mWordFileScores.length] = new WWHSearchBookMatches_FileScores_Object();
  697.   }
  698. }
  699.  
  700. function  WWHSearchBookMatches_AddMatches(ParamMatchString)
  701. {
  702.   var  MatchList = null;
  703.   var  WordFileScoresEntry;
  704.   var  MaxIndex;
  705.   var  Index;
  706.   var  FileID;
  707.   var  Score;
  708.  
  709.  
  710.   if (typeof ParamMatchString != "undefined")
  711.   {
  712.     MatchList = ParamMatchString.split(",");
  713.   }
  714.  
  715.   if ((MatchList != null) &&
  716.       (MatchList.length > 0))
  717.   {
  718.     WordFileScoresEntry = this.mWordFileScores[this.mMatchedWordIndex];
  719.  
  720.     // Add all entries to word file score entry
  721.     //
  722.     for (MaxIndex = MatchList.length, Index = 0 ; Index < MaxIndex ; Index += 2)
  723.     {
  724.       FileID = "i" + MatchList[Index];
  725.       Score  = MatchList[Index + 1];
  726.  
  727.       WordFileScoresEntry[FileID] = parseInt(Score);
  728.     }
  729.   }
  730. }
  731.  
  732. function  WWHSearchBookMatches_JoinFileScores()
  733. {
  734.   var  WordFileScoresEntry;
  735.  
  736.  
  737.   this.mFileScores = new WWHSearchBookMatches_FileScores_Object();
  738.   for (MaxIndex = this.mWordFileScores.length, Index = 0 ; Index < MaxIndex ; Index++)
  739.   {
  740.     WordFileScoresEntry = this.mWordFileScores[Index];
  741.  
  742.     if (Index == 0)
  743.     {
  744.       // Add all entries if first entry
  745.       //
  746.       this.mFileScores = WordFileScoresEntry;
  747.     }
  748.     else
  749.     {
  750.       // Remove all entries not found in results set
  751.       //
  752.       for (FileID in this.mFileScores)
  753.       {
  754.         if (typeof WordFileScoresEntry[FileID] == "number")
  755.         {
  756.           this.mFileScores[FileID] += WordFileScoresEntry[FileID];
  757.         }
  758.         else
  759.         {
  760.           delete this.mFileScores[FileID];
  761.         }
  762.       }
  763.     }
  764.   }
  765. }
  766.  
  767. function  WWHSearchBookMatches_FileScores_Object()
  768. {
  769. }
  770.  
  771. function  WWHSearchResults_Object()
  772. {
  773.   this.mSortedBy     = null;
  774.   this.mEntries      = new Array();
  775.   this.mMaxScore     = 0;
  776.   this.mDisplayIndex = 0;
  777.   this.mHTMLSegment  = new WWHStringBuffer_Object();
  778.   this.mEventString  = WWHPopup_EventString();
  779.  
  780.   this.fClear           = WWHSearchResults_Clear;
  781.   this.fAddEntry        = WWHSearchResults_AddEntry;
  782.   this.fSortByScore     = WWHSearchResults_SortByScore;
  783.   this.fSortByBookIndex = WWHSearchResults_SortByBookIndex;
  784.   this.fDisplayReset    = WWHSearchResults_DisplayReset;
  785.   this.fDisplayAdvance  = WWHSearchResults_DisplayAdvance;
  786.   this.fGetPopupAction  = WWHSearchResults_GetPopupAction;
  787.   this.fShowEntry       = WWHSearchResults_ShowEntry;
  788. }
  789.  
  790. function  WWHSearchResults_Clear()
  791. {
  792.   this.mSortedBy       = null;
  793.   this.mEntries.length = 0;
  794.   this.mMaxScore       = 0;
  795. }
  796.  
  797. function  WWHSearchResults_AddEntry(ParamBookIndex,
  798.                                     ParamFileIndex,
  799.                                     ParamScore,
  800.                                     ParamTitle)
  801. {
  802.   // Add a new entry
  803.   //
  804.   this.mEntries[this.mEntries.length] = new WWHSearchResultsEntry_Object(ParamBookIndex,
  805.                                                                          ParamFileIndex,
  806.                                                                          ParamScore,
  807.                                                                          ParamTitle);
  808.  
  809.   // Bump mMaxScore if necessary
  810.   //
  811.   if (ParamScore > this.mMaxScore)
  812.   {
  813.     this.mMaxScore = ParamScore;
  814.   }
  815. }
  816.  
  817. function  WWHSearchResults_SortByScore()
  818. {
  819.   this.mSortedBy = 1;  // By Score
  820.  
  821.   if (this.mEntries.length > 0)
  822.   {
  823.     this.mEntries = this.mEntries.sort(WWHSearchResultsEntry_ByScoreByBookIndexByTitleFileIndexURL);
  824.   }
  825. }
  826.  
  827. function  WWHSearchResults_SortByBookIndex()
  828. {
  829.   this.mSortedBy = 2;  // By BookIndex
  830.  
  831.   if (this.mEntries.length > 0)
  832.   {
  833.     this.mEntries = this.mEntries.sort(WWHSearchResultsEntry_ByBookIndexByScoreByTitleFileIndexURL);
  834.   }
  835. }
  836.  
  837. function  WWHSearchResults_DisplayReset()
  838. {
  839.   this.mDisplayIndex = 0;
  840. }
  841.  
  842. function  WWHSearchResults_DisplayAdvance()
  843. {
  844.   var  bSegmentCreated = false;
  845.   var  Settings = WWHFrame.WWHJavaScript.mSettings.mSearch;
  846.   var  HTML;
  847.   var  MaxHTMLSegmentSize;
  848.   var  BookList;
  849.   var  MaxIndex;
  850.   var  Index;
  851.   var  Entry;
  852.   var  ByBookDetect;
  853.  
  854.  
  855.   // Insure that there is something to display
  856.   //
  857.   if ((this.mSortedBy != null) &&
  858.       (this.mEntries.length > 0))
  859.   {
  860.     MaxHTMLSegmentSize = WWHFrame.WWHJavaScript.mMaxHTMLSegmentSize;
  861.     this.mHTMLSegment.fReset();
  862.     BookList = WWHFrame.WWHHelp.mBooks.mBookList;
  863.     ByBookDetect = -1;
  864.  
  865.     // If this is the first entry, display the headers and open the list
  866.     //
  867.     if (this.mDisplayIndex == 0)
  868.     {
  869.       HTML = "";
  870.  
  871.       HTML += "<p><nobr><b>";
  872.  
  873.       // Display column headers
  874.       //
  875.       if (Settings.mbShowRank)
  876.       {
  877.         HTML += WWHFrame.WWHJavaScript.mMessages.mSearchRankLabel + " ";
  878.       }
  879.       HTML += WWHFrame.WWHJavaScript.mMessages.mSearchTitleLabel;
  880.       if (Settings.mbShowBook)
  881.       {
  882.         if ((BookList.length > 1) &&  // More than one book exists
  883.             (this.mSortedBy == 1))    // By Score
  884.         {
  885.           HTML += ", " + WWHFrame.WWHJavaScript.mMessages.mSearchBookLabel;
  886.         }
  887.       }
  888.       HTML += "</b></nobr></p>\n";
  889.  
  890.       HTML += "<nobr><ol>\n";
  891.  
  892.       this.mHTMLSegment.fAppend(HTML);
  893.     }
  894.  
  895.     // Display result entries
  896.     //
  897.     MaxIndex = this.mEntries.length;
  898.     Index = this.mDisplayIndex;
  899.     while ((this.mHTMLSegment.fSize() < MaxHTMLSegmentSize) &&
  900.            (Index < MaxIndex))
  901.     {
  902.       HTML = "";
  903.  
  904.       Entry = this.mEntries[Index];
  905.  
  906.       if ((BookList.length > 1) &&  // More than one book exists
  907.           (this.mSortedBy == 2))    // By BookIndex
  908.       {
  909.         if (ByBookDetect != Entry.mBookIndex)
  910.         {
  911. // HACK BEN
  912. // ByBook only used for single books
  913. // No book title will be emitted
  914. //
  915. //          HTML += "<p><nobr> </nobr></p>";
  916. //          HTML += "<p><nobr>" + BookList[Entry.mBookIndex].mTitle + "</nobr></p>";
  917.  
  918.           ByBookDetect = Entry.mBookIndex;
  919.         }
  920.       }
  921.  
  922.       // Display Rank
  923.       //
  924.       if (Settings.mbShowRank)
  925.       {
  926.         HTML += "<li value=\"" + Math.floor((Entry.mScore / this.mMaxScore) * 100) + "\">";
  927.       }
  928.       else
  929.       {
  930.         HTML += "<li>";
  931.       }
  932.  
  933.       // Display Title
  934.       //
  935.       HTML += "<a href=\"javascript:fC(" + Index + ");\"" + this.fGetPopupAction(Index) + ">";
  936.       HTML += Entry.mTitle;
  937.       HTML += "</a>";
  938.  
  939.       // Display Book
  940.       //
  941.       if (Settings.mbShowBook)
  942.       {
  943.         if ((BookList.length > 1) &&  // More than one book exists
  944.             (this.mSortedBy == 1))    // By Score
  945.         {
  946.           HTML += ", " + BookList[Entry.mBookIndex].mTitle;
  947.         }
  948.       }
  949.  
  950.       HTML += "</li>\n";
  951.  
  952.       this.mHTMLSegment.fAppend(HTML);
  953.  
  954.       Index++;
  955.     }
  956.  
  957.     // Record current display index so we can pick up where we left off
  958.     //
  959.     this.mDisplayIndex = Index;
  960.     if (this.mHTMLSegment.fSize() > 0)
  961.     {
  962.       bSegmentCreated = true;
  963.     }
  964.  
  965.     // If this is the last entry, close the list
  966.     //
  967.     if (this.mDisplayIndex == this.mEntries.length)
  968.     {
  969.       this.mHTMLSegment.fAppend("</ol></nobr>\n");
  970.     }
  971.   }
  972.  
  973.   return bSegmentCreated;
  974. }
  975.  
  976. function  WWHSearchResults_GetPopupAction(ParamEntryIndex)
  977. {
  978.   var  PopupAction = "";
  979.  
  980.  
  981.   if (WWHFrame.WWHJavaScript.mSettings.mHoverText.mbEnabled)
  982.   {
  983.     PopupAction += " onMouseOver=\"fS('" + ParamEntryIndex + "', " + this.mEventString + ");\"";
  984.     PopupAction += " onMouseOut=\"fH();\"";
  985.   }
  986.  
  987.   return PopupAction;
  988. }
  989.  
  990. function  WWHSearchResults_ShowEntry(ParamIndex)
  991. {
  992.   var  Entry;
  993.   var  BookListEntry;
  994.   var  URL;
  995.  
  996.  
  997.   // Update highlight words
  998.   //
  999.   WWHFrame.WWHHighlightWords.fSetWordList(WWHStringUtilities_NormalizeSearchWords(WWHFrame.WWHSearch.mSavedSearchWords));
  1000.  
  1001.   // Display document
  1002.   //
  1003.   Entry = this.mEntries[ParamIndex];
  1004.   BookListEntry = WWHFrame.WWHHelp.mBooks.mBookList[Entry.mBookIndex];
  1005.   URL = WWHFrame.WWHHelp.mBaseURL + BookListEntry.mDirectory + BookListEntry.mFiles.fFileIndexToHREF(Entry.mFileIndex);
  1006.   WWHFrame.WWHHelp.fSetDocumentHREF(URL, false);
  1007. }
  1008.  
  1009. function  WWHSearchResultsEntry_Object(ParamBookIndex,
  1010.                                        ParamFileIndex,
  1011.                                        ParamScore,
  1012.                                        ParamTitle)
  1013. {
  1014.   this.mBookIndex = ParamBookIndex;
  1015.   this.mFileIndex = ParamFileIndex;
  1016.   this.mScore     = ParamScore;
  1017.   this.mTitle     = ParamTitle;
  1018. }
  1019.  
  1020. function  WWHSearchResultsEntry_ByScoreByBookIndexByTitleFileIndexURL(ParamAlphaEntry,
  1021.                                                                       ParamBetaEntry)
  1022. {
  1023.   var  Result;
  1024.  
  1025.  
  1026.   Result = WWHSearchResultsEntry_CompareByScore(ParamAlphaEntry, ParamBetaEntry);
  1027.   if (Result == 0)
  1028.   {
  1029.     Result = WWHSearchResultsEntry_CompareByBookIndex(ParamAlphaEntry, ParamBetaEntry);
  1030.   }
  1031.   if (Result == 0)
  1032.   {
  1033.     Result = WWHSearchResultsEntry_CompareByTitleFileIndexURL(ParamAlphaEntry, ParamBetaEntry);
  1034.   }
  1035.  
  1036.   return Result;
  1037. }
  1038.  
  1039. function  WWHSearchResultsEntry_ByBookIndexByScoreByTitleFileIndexURL(ParamAlphaEntry,
  1040.                                                                       ParamBetaEntry)
  1041. {
  1042.   var  Result;
  1043.  
  1044.  
  1045.   Result = WWHSearchResultsEntry_CompareByBookIndex(ParamAlphaEntry, ParamBetaEntry);
  1046.   if (Result == 0)
  1047.   {
  1048.     Result = WWHSearchResultsEntry_CompareByScore(ParamAlphaEntry, ParamBetaEntry);
  1049.   }
  1050.   if (Result == 0)
  1051.   {
  1052.     Result = WWHSearchResultsEntry_CompareByTitleFileIndexURL(ParamAlphaEntry, ParamBetaEntry);
  1053.   }
  1054.  
  1055.   return Result;
  1056. }
  1057.  
  1058. function  WWHSearchResultsEntry_CompareByScore(ParamAlphaEntry,
  1059.                                                ParamBetaEntry)
  1060. {
  1061.   var  Result = 0;
  1062.  
  1063.  
  1064.   // Sort by score
  1065.   //
  1066.   if (ParamAlphaEntry.mScore < ParamBetaEntry.mScore)
  1067.   {
  1068.     Result = 1;
  1069.   }
  1070.   else if (ParamAlphaEntry.mScore > ParamBetaEntry.mScore)
  1071.   {
  1072.     Result = -1;
  1073.   }
  1074.  
  1075.   return Result;
  1076. }
  1077.  
  1078. function  WWHSearchResultsEntry_CompareByBookIndex(ParamAlphaEntry,
  1079.                                                    ParamBetaEntry)
  1080. {
  1081.   var  Result = 0;
  1082.  
  1083.  
  1084.   if (ParamAlphaEntry.mBookIndex < ParamBetaEntry.mBookIndex)
  1085.   {
  1086.     Result = -1;
  1087.   }
  1088.   else if (ParamAlphaEntry.mBookIndex > ParamBetaEntry.mBookIndex)
  1089.   {
  1090.     Result = 1;
  1091.   }
  1092.  
  1093.   return Result;
  1094. }
  1095.  
  1096. function  WWHSearchResultsEntry_CompareByTitleFileIndexURL(ParamAlphaEntry,
  1097.                                                            ParamBetaEntry)
  1098. {
  1099.   var  Result = 0;
  1100.   var  BookList;
  1101.   var  AlphaBookEntry;
  1102.   var  BetaBookEntry;
  1103.   var  AlphaURL;
  1104.   var  BetaURL;
  1105.  
  1106.  
  1107.   // Sort by Title
  1108.   //
  1109.   if (ParamAlphaEntry.mTitle < ParamBetaEntry.mTitle)
  1110.   {
  1111.     Result = -1;
  1112.   }
  1113.   else if (ParamAlphaEntry.mTitle > ParamBetaEntry.mTitle)
  1114.   {
  1115.     Result = 1;
  1116.   }
  1117.   // Sort by FileIndex
  1118.   //
  1119.   else if (ParamAlphaEntry.mFileIndex < ParamBetaEntry.mFileIndex)
  1120.   {
  1121.     Result = -1;
  1122.   }
  1123.   else if (ParamAlphaEntry.mFileIndex > ParamBetaEntry.mFileIndex)
  1124.   {
  1125.     Result = 1;
  1126.   }
  1127.   // Sort by URL
  1128.   //
  1129.   else
  1130.   {
  1131.     BookList = WWHFrame.WWHHelp.mBooks.mBookList;
  1132.  
  1133.     AlphaBookEntry = BookList[ParamAlphaEntry.mBookIndex];
  1134.     BetaBookEntry  = BookList[ParamBetaEntry.mBookIndex];
  1135.  
  1136.     AlphaURL = WWHFrame.WWHHelp.mBaseURL + AlphaBookEntry.mDirectory + AlphaBookEntry.mFiles.fFileIndexToHREF(ParamAlphaEntry.mFileIndex);
  1137.     BetaURL  = WWHFrame.WWHHelp.mBaseURL + BetaBookEntry.mDirectory + BetaBookEntry.mFiles.fFileIndexToHREF(ParamBetaEntry.mFileIndex);
  1138.  
  1139.     if (AlphaURL < BetaURL)
  1140.     {
  1141.       Result = -1;
  1142.     }
  1143.     else if (AlphaURL > BetaURL)
  1144.     {
  1145.       Result = 1;
  1146.     }
  1147.   }
  1148.  
  1149.   return Result;
  1150. }
  1151.